package au.com.bluelink.scjp.chap5;

import java.io.*;

public class ExceptionTest {

	public static void main(String[] args) {

		try {
			TestEx.test();
		} catch (ArithmeticException e) {
			System.err.println("We are catching some type of exception here!");
			// e.printStackTrace();
		} finally {
			System.err.println("We craped ourselevs so cleaning up now...");
		}

		System.out.println("We caught the exception and recovered few!!");

		ReadData.test();
		
	}

}

class TestEx {
	public static void test() {
		doStuff();
	}

	static void doStuff() {
		doMoreStuff();
	}

	static void doMoreStuff() {
		int x = 5 / 0; // Can't divide by zero!
		// ArithmeticException is thrown here
	}
}

class ReadData {
	public static void test() {
		try {
			RandomAccessFile raf = new RandomAccessFile("myfile.txt", "r");
			byte b[] = new byte[1000];
			raf.readFully(b, 0, 1000);
		} catch (FileNotFoundException e) {
			System.err.println("File not found");
			System.err.println(e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println("IO Error");
			System.err.println(e.toString());
			e.printStackTrace();
		}
	}
}